package com.ruibang.glass.sale.controller;

import com.ruibang.glass.sale.domain.req.GSaleContractManReq;
import com.ruibang.glass.sale.domain.req.GSaleOrderReq;
import com.ruibang.glass.sale.domain.req.GSaleStatisticsManReq;
import com.ruibang.glass.sale.domain.req.SalePayProgressReq;
import com.ruibang.glass.sale.service.GSaleContractManagementService;
import com.ruibang.glass.sale.service.GSaleOrderManagementService;
import com.ruibang.glass.sale.service.SaleShippingApplicationService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@Api(tags = "统计报表")
@RestController
@RequestMapping("/api/glass/sale/statistics")
public class SaleStatisticsController {
    @Autowired
    private GSaleContractManagementService gSaleContractManagementService;

    @Autowired
    private GSaleOrderManagementService gSaleOrderManagementService;

    @Autowired
    private SaleShippingApplicationService saleShippingApplicationService;

    @PostMapping("contract/list")
    @ApiOperation(value = "销售合同报表", response = ResultBody.class)
    public ResultBody list(@RequestBody GSaleContractManReq gSaleReturnIventoryReq) {
        return ResultBody.success(gSaleContractManagementService.getNewPage(gSaleReturnIventoryReq));
    }

    @PostMapping("contract/export")
    @ApiOperation(value = "销售合同报表导出", response = ResultBody.class)
    public void export(@RequestBody GSaleContractManReq gSaleReturnIventoryReq, HttpServletResponse response) {
        gSaleContractManagementService.export(gSaleReturnIventoryReq, response);
    }

    @PostMapping("order/list")
    @ApiOperation(value = "销售订单报表", response = ResultBody.class)
    public ResultBody orderList(@RequestBody GSaleOrderReq gSaleOrderReq) {
        return ResultBody.success(gSaleOrderManagementService.getNewPage(gSaleOrderReq));
    }

    @PostMapping("order/export")
    @ApiOperation(value = "销售订单报表", response = ResultBody.class)
    public ResultBody orderExport(@RequestBody GSaleOrderReq gSaleOrderReq, HttpServletResponse response) {
        gSaleOrderManagementService.orderExport(gSaleOrderReq, response);
        return ResultBody.success();
    }

    @PostMapping("shipping/list")
    @ApiOperation(value = "销售出入库报表", response = ResultBody.class)
    public ResultBody shippingList(@RequestBody GSaleContractManReq saleContractManReq) {
        return ResultBody.success(saleShippingApplicationService.getNewPage(saleContractManReq));
    }

    @PostMapping("shipping/export")
    @ApiOperation(value = "销售出入库报表导出", response = ResultBody.class)
    public ResultBody shippingExport(@RequestBody GSaleContractManReq saleContractManReq, HttpServletResponse response) {
        saleShippingApplicationService.orderExport(saleContractManReq, response);
        return ResultBody.success();
    }

    @PostMapping("saleAmountOrQuality")
    @ApiOperation(value = "销售业绩", response = ResultBody.class)
    public ResultBody saleAmountOrQuality(@RequestBody GSaleStatisticsManReq saleStatisticsManReq) {
        return ResultBody.success(saleShippingApplicationService.getStatisticOrderDTOList(saleStatisticsManReq));
    }

    @PostMapping("payment/progress")
    @ApiOperation(value = "收款进度", response = ResultBody.class)
    public ResultBody paymentProgress(@RequestBody SalePayProgressReq salePayProgressReq) {
        return ResultBody.success(saleShippingApplicationService.paymentProgress(salePayProgressReq));
    }

    @PostMapping("dispute/statistics")
    @ApiOperation(value = "异议处理", response = ResultBody.class)
    public ResultBody disputeStatistic(@RequestBody SalePayProgressReq salePayProgressReq) {
        return ResultBody.success(saleShippingApplicationService.getGSaleDisputeLineDTOList(salePayProgressReq));
    }

}
